<template>
  <a-spin :spinning="confirmLoading">
     <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" slot="detail">
        <h3 class="title">基本信息</h3>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="认证类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authType">
               <span class="ant-form-text">{{model.authType_dictText}}</span>        
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="组织名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <span class="ant-form-text">{{model.orgName}}</span>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="ID" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <span class="ant-form-text">{{model.id}}</span>
            </a-form-model-item>
          </a-col>
          <!-- 个人认证 -->
          <div v-if="model.authType=='0'">
            <a-col :span="12">
             <a-form-model-item label="姓名" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contact">
             <span class="ant-form-text">{{model.contact}}</span>
            </a-form-model-item>
          </a-col>
            <a-col :span="12">
             <a-form-model-item label="手机号" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPhone">
               <span class="ant-form-text">{{model.contactPhone}}</span>        
            </a-form-model-item>
            </a-col>
            <a-col :span="12">
            <a-form-model-item label="身份证号" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idCardNo">
               <span class="ant-form-text">{{model.idCardNo}}</span>     
            </a-form-model-item>
          </a-col>  
          </div>
          <!-- 企业认证 -->
           <div v-else-if="model.authType=='1'">
            <a-col :span="12">
             <a-form-model-item label="联系人" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contact">
             <span class="ant-form-text">{{model.contact}}</span>
            </a-form-model-item>
          </a-col>
            <a-col :span="12">
             <a-form-model-item label="联系人手机号" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPhone">
               <span class="ant-form-text">{{model.contactPhone}}</span>        
            </a-form-model-item>
            </a-col> 
          </div>
           <a-col :span="12">
            <a-form-model-item label="QQ" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qq">
               <span class="ant-form-text">{{model.qq}}</span>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="邮箱" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="email">
              <span class="ant-form-text">{{model.email}}</span>        
            </a-form-model-item>
          </a-col>         
          <a-col :span="12">
            <a-form-model-item label="国家" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="country">
             <span class="ant-form-text">{{model.country_dictText}}</span>       
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="运营平台" :labelCol="labelCol" :wrapperCol="wrapperCol">
             <span class="ant-form-text">{{model.operationPlatform_dictText}}</span>  
            </a-form-model-item>
          </a-col>
        </a-row>
        <div v-if="model.authType=='1'">
        <a-divider />
        <a-row>
          <h3 class="title">企业信息</h3>
          <a-col :span="12">
          <a-form-model-item label="公司名称" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyName">
               <span class="ant-form-text">{{model.companyName}}</span>    
          </a-form-model-item>
             </a-col>
          <a-col :span="12">
           <a-form-model-item label="统一社会信用代码" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyCode">
              <span class="ant-form-text">{{model.companyCode}}</span>
            </a-form-model-item>
               </a-col>
            <a-col :span="12">
          <a-form-model-item label="法定代表人" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyLegalPerson">
              <span class="ant-form-text">{{model.companyLegalPerson}}</span>
          </a-form-model-item>
          </a-col>
          <a-col :span="12">
          <a-form-model-item label="法人身份证号" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idCardNo">
              <span class="ant-form-text">{{model.idCardNo}}</span>
          </a-form-model-item>
          </a-col>
          <a-col :span="12">
          <a-form-model-item label="成立时间" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyRegDate">
              <span class="ant-form-text">{{model.companyRegDate}}</span>
          </a-form-model-item>
             </a-col>
           <a-col :span="12">
            <a-form-model-item label="公司注册地址" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyRegAddress">
              <span class="ant-form-text">{{model.companyRegAddress}}</span>
            </a-form-model-item>
            </a-col>
             <a-col :span="12">
            <a-form-model-item label="公司办公地址" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyAddress">
              <span class="ant-form-text">{{model.companyAddress}}</span>
            </a-form-model-item>
         </a-col>
        </a-row>
        </div>
         <a-divider />
        <a-row>
          <h3 class="title">证件信息</h3>
          <div v-if="model.authType=='1'">
          <a-col :span="14">      
            <a-form-model-item label="法人与合同签署人是否为同一人" :label-col="{ xs: { span: 24 }, sm: { span: 10 } }" :wrapper-col="{ xs: { span: 24 }, sm: { span: 10 } }">
              <a-radio-group v-model="model.izSamePerson">
                 <a-radio value="1"> 是 </a-radio>
                 <a-radio value="0"> 否 </a-radio>    
              </a-radio-group>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="营业执照" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyIdPhoto">
              <j-image-upload :isMultiple="false" v-model="model.companyIdPhoto" class="idCardImgBack"></j-image-upload>
            </a-form-model-item>
          </a-col>
          </div>
          <a-col :span="12">
            <a-form-model-item required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idCardImg1">
              <span slot="label"> {{model.authType=='0'?'身份证':'身份证(法人)'}} </span>
              <div class="idCard" style="display: inline-flex">
               <j-image-upload v-model="model.idCardImg1" class="uploadImages" style="width: 100%"></j-image-upload>
               <j-image-upload v-model="model.idCardImg2" class="uploadImages" style="width: 100%; margin-left: 30px;"></j-image-upload>
             </div>  
            </a-form-model-item>
          </a-col>
          <a-col :span="12" v-if="model.izSamePerson=='0'">
            <a-form-model-item label="身份证(合同签署人)" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="idCardImg3">
             <div class="idCard" style="display: inline-flex">
               <j-image-upload v-model="model.idCardImg3" class="uploadImages" style="width: 100%"></j-image-upload>
               <j-image-upload v-model="model.idCardImg4" class="uploadImages" style="width: 100%; margin-left: 30px;"></j-image-upload>
             </div>  
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="合同" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessContract">
              <j-image-upload  v-model="model.businessContract" class="idCardImgBack"></j-image-upload>
            </a-form-model-item>
          </a-col>
           <a-col :span="12" v-if="model.authType=='1' && model.izSamePerson=='0'">
            <a-form-model-item label="授权书" required :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authorizationLetter">
               <a-col :span="12">
                  <j-upload v-model="model.authorizationLetter" text="上传附件" :multiple="false"></j-upload>
               </a-col>
            </a-form-model-item>
          </a-col>
        </a-row>
         <a-divider />
         <a-row>
          <h3 class="title">系统信息</h3>
          <a-col :span="12">
            <a-form-model-item label="最后提交人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <span class="ant-form-text">{{model.authCommitUser}} </span>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <span class="ant-form-text">{{model.authCommitTime}}</span>
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="通过时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <span class="ant-form-text">{{model.authPassTime}}</span>
            </a-form-model-item>
          </a-col>
         </a-row>
      </a-form-model>
    </j-form-container>
      <a-form-model ref="formCheck" :model="formModel" :rules="validatorRules">
        <a-row>
          <a-col :span="12" v-if="isRefuseReson">
            <a-form-model-item label="驳回原因" prop="reason" :label-col="labelCol" :wrapper-col="wrapperCol">
                <a-textarea placeholder="请输入驳回原因" v-model="formModel.reason" allow-clear/>
                <div></div>
            </a-form-model-item>
          </a-col>
        </a-row>
         <a-row style="text-align: center">
         <a-button size="large" :loading="confirmLoading" type="primary" @click="auditHandle" style="margin-right: 50px;">
           审核通过
        </a-button>
         <a-button v-if="isRefuseReson == false" size="large" key="submit"  @click="isRefuseReson=true">驳回</a-button>
         <a-button v-if="isRefuseReson" size="large" key="submit" :loading="loading" @click="refuseHandle">驳回</a-button>
         </a-row>
      </a-form-model>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'BaseAuditForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      model: {  },
      formModel:{
        reason:'',
      },     
      labelCol: {
        xs: { span: 24 },
        sm: { span: 9 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 },
      },
      confirmLoading: false,
      isRefuseReson:false,
      loading:false,
       validatorRules: {
         reason:[{ required: true, message: '请填写驳回原因后再次点击驳回按钮!' }]
      },
     url: {
        queryById: '/finance/baseSettlementOrgAuth/queryById',  //通过id查询组织认证信息
        check:'/finance/baseSettlementOrgAuth/check',
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      // this.edit(this.modelDefault);
      this.model = Object.assign({}, this.modelDefault)
      this.visible = true
    },
    edit(record) {
      // this.model = Object.assign({}, record)
      this.getBaseSettlementOrgAuthInfo(record)
      this.visible = true
    },
      //根据id查询组织认证信息
    getBaseSettlementOrgAuthInfo(record){
       const that=this
      getAction(that.url.queryById, {id: record.id})
         .then(res=>{
          if(res.success){
             res.result.authType=res.result.authType?res.result.authType:'0'
             that.model=res.result
             that.model.orgName=record.name
            // that.model.authType_dictText=res.result.authType
          }else{
            that.$message.warning(res.result)
          }
         })
    },
    //驳回
    refuseHandle(){          
         this.$refs.formCheck.validate(valid => {   
        if (valid) {
            this.submitInfo(0)
        } else {
          return false;
        }
      });    
    },
    //审核通过
    auditHandle(){
       this.isRefuseReson=false;
       this.submitInfo(1)
    },
    
    submitInfo(type) {     
       const that = this
        that.confirmLoading = true
        that.loading=true
        	// 1是 通过  0否 驳回
         const vo={
           id:that.model.id,
           reason:type==0?that.formModel.reason:'',
           type:type 
         }
          httpAction(that.url.check,vo,'put')
              .then((res) => {
                if (res.success) {
                  that.$message.success(res.message)
                  that.$emit('ok')
                } else {
                  that.$message.warning(res.message)
                }
              })
              .finally(() => {
                that.confirmLoading = false
                that.loading=false
              }) 
    },
  },
}
</script>
<style scoped>
.title {
  font-weight: bold;
  margin-left: 3%;
}
.operating {
  padding-right: 30px;
}
</style>